package com.os.start.controller;

import com.os.core.common.JsonResult;
import com.os.start.mapper.UserInfoAnnotationDao;
import com.os.start.mapper.UserInfoDao;
import com.os.start.pojo.UserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * Created by Matt on 2022-01-04.
 */

@RestController
public class MapperController {

    @Autowired
    private UserInfoDao userInfoDao;

    //引入sl4j
    final static Logger log = LoggerFactory.getLogger(MapperController.class);

    @Autowired
    private UserInfoAnnotationDao userInfoAnnotationDao;

    @RequestMapping("/queryUser")
    public JsonResult queryUser(){
        List<UserInfo> list = userInfoDao.queryUser();
        return new JsonResult(true, list);
    }

    @RequestMapping("/getMapper")
    public JsonResult testMapper(){
        UserInfo userInfo = userInfoDao.getUserById("1");
        return new JsonResult(true, userInfo);
    }

    @RequestMapping("/updateMapper")
    public JsonResult updateMapper(){
        UserInfo userInfo = new UserInfo();
        userInfo.setId("1");
        userInfo.setName("哈哈哈");
        userInfo.setSex("女");
        userInfo.setAge(1);
        int count = userInfoDao.updateUser(userInfo);
        return new JsonResult(true, count);
    }

    @RequestMapping("/insertMapper")
    public JsonResult insertMapper(){
        UserInfo userInfo = new UserInfo();
        userInfo.setId("2");
        userInfo.setName("hello");
        userInfo.setSex("女");
        userInfo.setAge(1);
        int count = userInfoDao.insertUser(userInfo);
        return new JsonResult(true, count);
    }

    @RequestMapping("/deleteUserById")
    public JsonResult deleteUserById(){
        int count = userInfoDao.deleteUserById("1");
        return new JsonResult(true, count);
    }

    @RequestMapping("/queryUserAnnotation")
    public JsonResult queryUserAnnotation(){
        List<UserInfo> list = userInfoAnnotationDao.queryUser();
        log.info("查询日志测试，当前时间：{}，操作用户：{}", new Date(), "Matt");
        return new JsonResult(true, list);
    }

    @RequestMapping("/getUserAnnotation")
    public JsonResult getUserAnnotation(){
        UserInfo userInfo = userInfoAnnotationDao.getUserById("scs");
        return new JsonResult(true, userInfo);
    }

    @RequestMapping("/updateUserAnnotation")
    public JsonResult updateUserAnnotation(){
        UserInfo userInfo = new UserInfo();
        userInfo.setId("1");
        userInfo.setName("哈哈哈12");
        userInfo.setSex("女");
        userInfo.setAge(1);
        int count = userInfoAnnotationDao.updateUser(userInfo);
        return new JsonResult(true, count);
    }

    @RequestMapping("/insertUserAnnotation")
    public JsonResult insertUserAnnotation(){
        UserInfo userInfo = new UserInfo();
        userInfo.setId("21");
        userInfo.setName("hello");
        userInfo.setSex("女");
        userInfo.setAge(1);
        int count = userInfoAnnotationDao.insertUser(userInfo);
        return new JsonResult(true, count);
    }

    @RequestMapping("/deleteUserAnnotation")
    public JsonResult deleteUserAnnotation(){
        int count = userInfoAnnotationDao.deleteUserById("1");
        return new JsonResult(true, count);
    }

    @RequestMapping("/one/testInterceptor")
    public JsonResult testInterceptor(){
        return new JsonResult(true);
    }

    @RequestMapping("/two/testInterceptorTwo")
    public JsonResult testInterceptorTwo(){
        return new JsonResult(true);
    }
}
